import torch
from PIL import Image
import torchvision.transforms as T

import os, torch
local_dir = os.path.expanduser('~/code/study/dinov2')
dinov2_vitb14 = torch.hub.load(
    local_dir,
    'dinov2_vitb14',
    source='local',      # 关键：从本地源码加载
    trust_repo=True,
    pretrained=True
)

                                                                                            
# dinov2_vitb14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14')
print(f'model loaded successfully')

img = Image.open('models/FOUND/data/examples/VOC_000030.jpg')

transform = T.Compose([
T.Resize(224),
T.CenterCrop(224),
T.ToTensor(),
T.Normalize(mean=[0.5], std=[0.5]),
])

img = transform(img)[:3].unsqueeze(0)
print(f'image transformed successfully, shape: {img.shape}')

with torch.no_grad():
    features = dinov2_vitb14(img, is_training=True)
